package com.xsh.config;

import com.rabbitmq.tools.json.JSONUtil;
import com.xsh.pojo.Type;
import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;

/**
 * @author 李星
 * @date 2020/11/30 18:40
 */
public class DateConfig implements Converter<String, Date> {
    @Override
    public Date convert(String s) {
        try {
            return new SimpleDateFormat("yyyt-MM-dd HH:mm:ss").parse(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    public static void main(String[] args) {


        LocalDate begin= null;
        LocalDate localDate = begin.plusMonths(3);
        System.out.println(localDate);


//        String user = "1";
//        int length = Optional.ofNullable(user).orElse("123").length();
//        System.out.println(length);
//
//        String[] userList = {"123","456","789"};
//        Optional.ofNullable(userList).orElse(new String[]).forEach(user -> {
//            System.out.println(user);
//        });
//
//        Optional<Type> type = Optional.ofNullable(new Type());
//        if (type.isPresent()){
//            System.out.println(true);
//        }




//
//        LocalDate localDate = LocalDate.of(2021,01,03);
//        for (int i = 1; i <=3 ; i++) {
//            LocalDate localDate1 = localDate.minusMonths(i);
//            String yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd").format(localDate1);
//            System.out.println(yyyyMMdd);
//        }
//        //动态修改月份（往前推）
//        LocalDate date = localDate.minusMonths(5);


        String systemDate = "20210203";
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");

        try {
            Date date = formatter.parse(systemDate);
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            for (int i = 1; i < 4; i++) {
                c.add(Calendar.MONTH, -1);
                Date m = c.getTime();
                System.out.println(formatter.format(m));
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }



//    public static void main(String[] args) {
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        String dateStr = "2019-01-03";
//
//        try {
//            Date date = simpleDateFormat.parse(dateStr);
//            System.out.println(date);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//    }
}
